<template>
	<div>
		<van-nav-bar title="京东注册" left-text="返回" left-arrow @click-left="$router.go(-1)" />

		<van-form @submit="onSubmit">
			<van-cell-group inset>
				<van-field v-model="num" name="tel" label="请输入手机号" :rules="[{ pattern, message: '请填写正确的手机号码' }]" />
			</van-cell-group>
			<div style="margin: 16px;">
				<van-button round block type="primary" native-type="submit"
					color="linear-gradient(to right, #ff6034, #ee0a24)">
					下一步
				</van-button>
			</div>
		</van-form>
	</div>
</template>
<script setup lang='ts'>
// 注册
import { Register } from '@/api/loginapi'

import { ref,type Ref } from 'vue';

import { useRouter } from 'vue-router';

import { Dialog } from 'vant';


const num: Ref<string> = ref('')
console.log(num);


const pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
console.log(pattern.test('num'));

const router = useRouter()


const onSubmit = (values: { tel: string }) => {
	Register(values).then((res: any) => {
		console.log(res);
		if (res.code == 200) {
			Dialog.confirm({
				title:'提示',
				message:`将向手机号${num.value}发送短信验证码`,
				confirmButtonText: '立即注册'
			}).then(() => {		// 确认
				// on confirm
				// router.push('/register/step2?tel='+values.tel)
				router.push({path:'/register/step2',query:{tel:values.tel}})
			//	userStore.setNumcontent(num.value)
			}).catch(() => {	// 取消
				console.log("aaa");

				// on cancel
			});
		}
	})

}





</script>
<style scoped>

</style>